package b1.scenes.home.wanted
{
	import b1.controls.basic.BasicButton;
	import b1.net.*;
	import b1.scenes.crime.*;
	import b1.scenes.detect.*;
	import b1.scenes.home.*;
	import b1.scenes.home.police.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.ColorMatrixFilter;
	import flash.ui.Mouse;
	import flash.text.*;
	import flash.media.Sound;
	
	public class WantedTab extends Sprite
	{
		public var wantedDialog:WantedDialog;
		private var lenth:Number;
		private var curPage:Number;
		private var closeButton:BasicButton;
		private var parentScene:Sprite;
		private static var instance:WantedTab;
		public var topPlayers:Array;
//		public var leftButton:Sprite;
//		public var rightButton:Sprite;
		
		public function WantedTab()
		{
			curPage = 0;
			lenth = 2;
			var CloseButton:Class = ResourceHelper.getInstance().getClassByName("CloseButton2");
			closeButton = new BasicButton(CloseButton);
			closeButton.x = 540;
			closeButton.y = 60;
			
//			var LeftButton:Class = ResourceHelper.getInstance().getClassByName("TabPagePageUp");
//			leftButton = new LeftButton();
//			leftButton.x = 100;
//			leftButton.y = 550;
//			var RightButton:Class = ResourceHelper.getInstance().getClassByName("TabPagePageDown");
//			rightButton = new RightButton();
//			rightButton.x = 600;
//			rightButton.y = 550;
//			firstPage.addEventListener(MouseEvent.CLICK, onFirstPageClick);
//			firstPage.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
//			firstPage.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);		
		}
		
//		private function showNextPage():void
//		{
//			removeChild(wantedDialog);
//			if(curPage == 0)
//			{
//				curPage ++;
//				getTopAnimalsComplete(topAnimals,curPage);
//			}
//			else if(curPage == lenth - 1)
//			{
//				curPage = 0;
//				getTopAnimalsComplete(topAnimals,curPage);
//			}
//		}
//		
//		private function onLeftClick(event:MouseEvent):void
//		{
//			
//			if(curPage>0) curPage--;
//			wantedDialog.changePageTo(topPlayers,curPage);
//			
//		}
//		
//		private function onRightClick(event:MouseEvent):void
//		{
//		
//			if(curPage<2) curPage++;
//			wantedDialog.changePageTo(topPlayers,curPage);
//			
//		}
		
		private function closeTab(event:MouseEvent):void
		{
			this.parent.removeChild(this);
		}

		public static function getInstance():WantedTab
		{
			if (!instance)
				instance = new WantedTab();
			return instance;
		}
		
		public function open(parentScene:Sprite):void
		{
			if (!parentScene.contains(this))
			{
				this.parentScene = parentScene;
				ServerHelper.getInstance().getTopAnimals(10, getTopAnimalsComplete);
			}
		}
		
		public function getTopAnimalsComplete(players:Array, curPage:int = 0):void
		{
			if (!parentScene.contains(this))
			{
				parentScene.addChild(this);
			}
			topPlayers = players;
			wantedDialog = new WantedDialog(players);
			wantedDialog.x = 0;
			wantedDialog.y = 0;
			addChild(wantedDialog);
			addChild(closeButton);
			closeButton.addEventListener(MouseEvent.CLICK,closeTab);
			
			//播放音效
			var SoundButton1:Class = ResourceHelper.getInstance().getClassByName("SoundButton1");
			var sound:Sound = new SoundButton1();
			sound.play();
			 
			Store.getInstance().close();
			CrimeDialog.getInstance().close();
			DetectDiaglog.getInstance().close();
			PoliceStation.getInstance().close();
			BottomNavigator.getInstance().hide();
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			event.target.filters = [new ColorMatrixFilter(
				[1,0,0,0,-15,
			     0,1,0,0,-15,
			     0,0,1,0,-15,
			     0,0,0,1,0 ])];
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			event.target.filters = null;
		}
		
		public function close():void
		{
			if (this.parent != null)
				this.parent.removeChild(this);
		}
	}
}